|
|
|
|
|
|
|
In the spirit of object-oriented programming, you can take the idea of a wrapper function one step further and create a wrapper class. You can use the sample class, ComputerInfo, to manipulate the Windows computer name. You can manually change the computer name from the Network Control Panel, shown in Figure 20.3. |
|
|
|
|
|
|
|
|
Figure 20.3
The API calls in the ComputerInfo class can set your computer name. |
|
|
|
|
|
|
|
|
Two API calls are used to retrieve and set the computer name: GetComputerName and SetComputerName. Your class will encapsulate these functions into a single property that is easier to deal with from Visual Basic. Listing 20.2 shows the code for the ComputerInfo class, which includes one property and one event. |
|
|
|
|
|
|
|
|
Listing 20.2 COMPNAME.ZIPThe ComputerInfo Class Sets the Windows Computer Name |
|
|
|
|
|
|
|
|
Option Explicit
'Notice these API declarations are private - we don't want them accessed directly
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function SetComputerName Lib "kernel32" Alias "SetComputerNameA" _
(ByVal lpComputerName As String) As Long
Public Event RebootNeeded()
Public Property Get ComputerName() As String
Dim sName As String
Dim lRetVal As Long
Dim iPos As Integer |
|
|
|
|
|